if __name__ == '__main__':  
    import socket  
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  
    sock.bind(('localhost', 8001))  
    sock.listen(5)  
    connection,address = sock.accept()  
    i = 0;
    while True:  
        try:  
            connection.settimeout(10)
            i = i+1
            buf = ''
            while True:
               buf += connection.recv(1024)  
               print buf
               if buf.find('</Eadp>'):  
                   connection.send('welcome to server!</Eadp>')  
                   break;
               else:  
                   connection.send('please go out!</Eadp>')  
                   break;
        except socket.timeout:  
            print 'time out and send period data' 
            buf1 = 'Period data %d</Eadp>'%(i)
            connection.send(buf1)  
    connection.close()  